package com.whys;

import java.util.Scanner;

public class ArrayDemo01 {
    public static void main(String[] args) {
        // int [] arr = new int[4]    int []  arr = {1,2,3}

        // 数组求和
        int[] a  = new int[5];
        // 调用打印
        Scanner sc = new Scanner(System.in);


        for (int i = 0; i <a.length ; i++) {
            System.out.println("请输入第"+(i+1)+"个元素");
            a[i]  = sc.nextInt();
        }

        System.out.println("数组的元素为:");
        for (int i = 0; i < a.length ; i++) {
            System.out.println(a[i]+"  ");
        }

        int sum =0; // 初始值
        for (int i = 0; i <a.length ; i++) {
            sum += a[i];   //sum = sum + a[i]
        }
        System.out.println("总和为"+sum);

    }
}
